#!/usr/bin/python
# -*- coding: UTF-8 -*-
from flaskr.CommonUtils.DBUtils import *


class InitCompareData:
    """
    初始化比对数据
    """

    def __init__(self):
        pass

    # 初始化 gauss 或者 pg 的数据
    @staticmethod
    def init_gauss_or_pg_data(db_utils_i: DBUtils, table_name_i: str, sql_string_i: str):
        result = db_utils_i.exec_sql_get_result_from_gauss_or_pg(sql_string_i)
        print(str(result))
        DBUtils.insert_sqlite3_table_from_data_list(table_name_i, result)

    # 初始化 gauss plan sit 的表结构数据到 sqlite3 数据库
    @staticmethod
    def init_gauss_tzq_log_sit_data_to_sqlite3():
        source_string = "gauss_tzq_log_dev"
        # 先删除存量数据
        DBUtils.execute_sqlite3_scripts("delete from compare_table where source = '" + source_string + "';")
        # 再重刷数据
        db_utils = DBUtils()
        db_utils.value["host"] = "192.168.48.158"
        db_utils.value["port"] = "8000"
        db_utils.value["dbname"] = "tzq_log_dev_db"
        db_utils.value["user"] = "tzq_log"
        db_utils.value["password"] = "Tzq@12345"
        sql_string = ("select '" + source_string + "' as source "
                      ",schema, table_name, table_comment, column_name, data_type "
                      ",column_default as data_default "
                      ",is_nullable as nullable "
                      ",pkey "
                      ",column_comment "
                      " from tab_info_v t ;")
        table_name = "compare_table"
        InitCompareData.init_gauss_or_pg_data(db_utils, table_name, sql_string)


if __name__ == '__main__':
    # 初始化 gauss plan sit 的表结构数据到 sqlite3 数据库
    InitCompareData.init_gauss_tzq_log_sit_data_to_sqlite3()

